The default controllers, TextFieldController and SearchBarController, work well with UIKit.
If you want to use another component, such as a third-party input view, or introduce custom behaviors to UIKit components, you can create a controller that conforms to the SearchBoxController protocol.
InstantSearch provides the SearchBar SwiftUI view, which you can embed in your views.
It uses SearchBoxObservableController as a data model, which implements the SearchBoxController protocol for SwiftUI.
SearchBoxObservableController must be connected to the SearchBoxConnector or SearchBoxInteractor like any other SearchBoxController implementation.
Copy
Ask AI
struct ContentView: View {@ObservedObject var searchBoxObservable: SearchBoxObservableController = .init()@State var isEditing = falsevar body: some View { SearchBar(text: $searchBoxObservable.query, isEditing: $isEditing, onSubmit: searchBoxObservable.submit)}}
If you prefer to create a custom SwiftUI view that handles the query input, you can directly use the SearchBoxObservableController as a data model.
It provides the query property along with the submit function to streamline the design process of your custom SwiftUI view.